﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GamePlugin.Logics.Data;
using GamePlugin.IO;
using GamePlugin.Logics.Game;
using GamePlugin.Logics.Core;
using GamePlugin.Logics.Data.Auction;

namespace GamePlugin.Logics
{
    public class Workspace
    {
        public AuctionItem AuctionItem
        {
            get;
            set;
        }

        public AuctionItemList AuctionItemList
        {
            get;
            set;
        }

        public SearchItemCompare SearchItemCompare
        {
            get;
            set;
        }

        public SearchItem LastSearchItem
        {
            get;
            set;
        }

        public SearchItem SearchItem
        {
            get;
            set;
        }

        public LengendItemList LengendItemList
        {
            get;
            set;
        }

        public PropertyItemList PropertyItemList
        {
            get;
            set;
        }

        public SearchInfoItemList SearchInfoItemList
        {
            get;
            set;
        }

        public DiabloPluginGame DiabloPluginGame
        {
            get;
            set;
        }

        public SearchOptionData SearchOptionData
        {
            get;
            set;
        }

        public StateLogData StateLogData
        {
            get;
            set;
        }

        private Workspace()
        {
            //this.Init();
        }

        private void Init()
        {
            this.LoadAll();

            StateLogData = new StateLogData();
            DiabloPluginGame = new DiabloPluginGame();

            Workspace.Instance.LastSearchItem = null;
            this.SearchItemCompare = new SearchItemCompare();
        }

        public void LoadAll()
        {
            PropertyItemList = new PropertyItemList();
            LengendItemList = new LengendItemList();
            IOManager.Instance.LoadPropertyData(LengendItemList, PropertyItemList, IOManager.Instance.DataFolderPath + "//DefaultProperty.prp");

            SearchInfoItemList = new SearchInfoItemList();
            SearchOptionData = new SearchOptionData();
            IOManager.Instance.LoadSearchData(Workspace.Instance.SearchOptionData, SearchInfoItemList, IOManager.Instance.DataFolderPath + "//DefaultList.pak");

            AuctionItemList = new AuctionItemList();
            IOManager.Instance.LoadAuctionData(Workspace.Instance.AuctionItemList, IOManager.Instance.DataFolderPath + "//DefaultAuction.pak");
        }

        public void SaveAll()
        {
            IOManager.Instance.SavePropertyData(LengendItemList, PropertyItemList, IOManager.Instance.DataFolderPath + "//DefaultProperty.prp");
            IOManager.Instance.SaveSearchData(SearchOptionData, SearchInfoItemList, IOManager.Instance.DataFolderPath + "//DefaultList.pak");
            IOManager.Instance.SaveAuctionData(AuctionItemList, IOManager.Instance.DataFolderPath + "//DefaultAuction.pak");
        }

        private static Workspace _Instance = null;
        public static Workspace Instance
        {
            get
            {
                if (_Instance == null)
                {
                    _Instance = new Workspace();
                    _Instance.Init();
                }
                return _Instance;
            }
        }
    }
}
